package com.caopeng.javaee.controller;

import com.caopeng.javaee.entity.work;
import com.caopeng.javaee.service.CourseService;
import com.caopeng.javaee.service.CourseStudentService;
import com.caopeng.javaee.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @program: javaee
 * @description: 作业的逻辑处理部分
 * @author: caopeng
 * @create: 2018-12-14 16:56
 **/
@Controller
public class WorkController {
    @Autowired
    WorkService workService;
    @Autowired
    CourseStudentService courseStudentService;
    @Autowired
    CourseService courseService;
@RequestMapping(value = "Workindex")
    public String Workindex(HttpSession session, Model model){
//    System.out.println("跳转主页面");
    //找该课程的作业
    String courseid=session.getAttribute("course_id").toString();
//    System.out.println(courseid+"课程id为:");
    List<work>  homeworklist=workService.WfindbyCourseid(courseid);
//    System.out.println(homeworklist.size()+"获取到的作业长度");
    int peopleNumber=courseStudentService.Courseidfindstudentlist(Integer.valueOf(courseid)).size();
    String coursename=courseService.CfindById(Integer.valueOf(courseid)).getcourseName();
    model.addAttribute("homeworklist",homeworklist);
    model.addAttribute("peopleNumber",peopleNumber);
    model.addAttribute("coursename",coursename);
    return "workindex";
    }
    @RequestMapping(value = "addwork")
    public  String addwork(){


        return "workadd";
    }
}

